import { Toast } from 'antd-mobile'
import { createAction, NavigationActions } from '../../utils/index'
import * as Libs from '../../utils/Libs'
import * as forecastService from '../../services/forecast/forecastService'



const initState = {
  titles: {},
  contents: [],
}

export default {
  namespace: 'forecast',
  state: initState,
  reducers: {
    initState(state, { payload}) {
      return {...initState}
    },
    initTzYc(state, { payload}) {
      return {...state, tzyc: initTzyc}
    },
    changeState(state, {payload}) {
      return {...state, ...payload}
    }
  },
  effects: {
    *getForecast({ payload }, { call, select, put}) {
      const params = {}
      params.startTime = payload.startTime
      params.endTime = payload.endTime
      const resp = yield call(forecastService.getForecast, params)
      if (resp.resultCode !== 200) {
        Toast.info(resp.msg, 1)
        return false
      }
      const respData = resp.data || []
      const titles = forecastService.buildTitles(respData[0] || {})
      const contents = forecastService.buildContents(respData)
      console.log('titles :', titles)
      yield put(createAction("changeState")({
        titles: titles,
        contents: contents
      }))
    },
  },
  subscriptions: {
  },
}
